package pack_4_14_2;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;

public class MyApplicationEventPublisherAware implements ApplicationEventPublisherAware {
    private ApplicationEventPublisher publisher;
    public MyApplicationEventPublisherAware() {
        System.out.println("MyApplicationEventPublisherAware create..");
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.publisher = applicationEventPublisher;
        System.out.println("MyApplicationEventPublisherAware setApplicationEventPublisher("+applicationEventPublisher+")");
    }

    public void sendEmail(String address, String text) {
        System.out.println("MyApplicationEventPublisherAware sendEmail("+address+","+text+")");
        MyEvent event = new MyEvent(this, address, text);
        publisher.publishEvent(event);
    }
}
